package study.javabasic.Thread;


public class SleepWaitDemo {

    public static void main(String[] args) {
     final   Object lock=new Object();

        new Thread(new Runnable() {
            public void run() {
                System.out.println("thread A waiting lock");
                synchronized (lock){
                    System.out.println("thread A get lock");
                    try {
                        Thread.sleep(2000);
                        System.out.println("thread A do something");
                        lock.wait(1000);
                        System.out.println("thread A is done");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(new Runnable() {
            public void run() {
                System.out.println("thread B waiting lock");
                synchronized (lock){
                    System.out.println("thread B get lock");
                    try {
                        System.out.println("thread B do something");
                        Thread.sleep(1000);
                        System.out.println("thread B is done");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }).start();



    }
}
